package refactoring.replaceSubclassWithDelegate.refactoring;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * <描述>
 *
 * @author timothy.yang cloudwise
 * @since 2022-05-23 23:03
 */
@Data
@NoArgsConstructor
public class Bird {

    private String type;
    private String name;
    private String plumage;
    private BirdDelegate speciesDelegate;

    public Bird(BirdParam birdParam) {
        this.name = birdParam.getName();
        this.plumage = birdParam.getPlumage();
        this.speciesDelegate = this.selectSpeciesDelegate(birdParam);
    }

    public enum BirdType {
        EuropeanSwallow, AfricanSwallow, NorwegianBlueParrot
    }

    public BirdDelegate selectSpeciesDelegate(BirdParam birdParam) {
        switch (birdParam.getType()) {
            case EuropeanSwallow:
                return new EuropeanSwallowDelegate(birdParam, this);
            case AfricanSwallow:
                return new AfricanSwallowDelegate(birdParam, this);
            case NorwegianBlueParrot:
                return new NorwegianBlueParrotDelegate(birdParam, this);
            default:
                return new BirdDelegate(birdParam, this);
        }
    }

    public static Bird createBird(BirdParam param) {
        return new Bird(param);
    }

    public String plumage() {
        return this.getPlumage();
    }

    public Integer airSpeedVelocity() {
        if (this.speciesDelegate != null) {
            this.speciesDelegate.airSpeedVelocity();
        }
        return null;
    }
}
